package com.singzi.leetcode.jianzhiOffer2;

public class T0013 {
}
class NumMatrix {
    int [][]matrx, up, down, left, right;
    int sum;
    public NumMatrix(int[][] matrix) {
        matrx = matrix;
        int m = matrix.length, n = matrix[0].length;
        up = new int[m][n];
        for(int i = 0;i < n;i++){
            up[0][i] = matrix[0][i];
        }
        for(int i = 1;i < m;i++){
            for(int j = 0;j < n;j++){
                up[i][j] = up[i-1][j] + matrix[i][j];
            }
        }

    }

    public int sumRegion(int row1, int col1, int row2, int col2) {
        sum = 0;
       for(int i = col1;i <= col2;i++){
           if(row1 > 0) sum += up[row2][i] - up[row1-1][i];
           else sum+= up[row2][i];
       }
        return  sum;

    }
}